module diansha {
	export class index extends eui.Component implements eui.UIComponent {
		private rect: eui.Rect;
		where: eui.Label
		wherestr: string;
		private tab: eui.TabBar;
		private vs: eui.ViewStack;
		private arr: eui.ArrayCollection = new eui.ArrayCollection();
		private change: eui.ToggleButton;
		private close: eui.Button;
		private btngroup: eui.Group;
		private qitagroup: eui.Group;
		private biggroup: eui.Group;
		private vsgroup: eui.Group;
		private mainout: eui.Panel;
		private mainoutbtn: eui.Button;
		private zhanghao: eui.Button;
		private geren: diansha.vs;
		private heros: diansha.vs;
		private zhuangbei: diansha.vs;
		private chongwu: diansha.vs;
		private shenqi: diansha.vs;
		private bgmusic: eui.ToggleButton;//默认弹起/弹起为false/按下为true
		private othermusic: eui.ToggleButton;
		private mainoutpointinit: egret.Point = new egret.Point();
		public constructor() {
			super();
			this.addEventListener(eui.UIEvent.COMPLETE, this.onComplete, this);

		}
		protected childrenCreated(): void {
			setInterval(() => {
				this.farme();

			}, 2000)

		}


		protected partAdded(partName: string, instance: any): void {
			super.partAdded(partName, instance);
		}

		private farme() {
			let ss = diansha.shuxing_manage.getinstance().wudao(0, 5);
		
				// let liliangaddpaopao = diansha.paopao_factory.getinstance().get(ss.liliangadd, new egret.Point(0, 200), new egret.Point(200, 10), 3000, ss.errdetail);
				// let minjieaddpaopao = diansha.paopao_factory.getinstance().get(ss.minjieadd, new egret.Point(0, 200), new egret.Point(300, 10), 3000, ss.errdetail);
				// let zhiliaddpaopao = diansha.paopao_factory.getinstance().get(ss.zhiliadd, new egret.Point(0, 200), new egret.Point(400, 10), 3000, ss.errdetail);
				// cores.getinstatic().index.qitagroup.addChild(liliangaddpaopao);
				// cores.getinstatic().index.qitagroup.addChild(minjieaddpaopao);
				// cores.getinstatic().index.qitagroup.addChild(zhiliaddpaopao);
			

		}
		/**
		 * 加载网络图片
		 */
		private load() {
			// console.log(res_manage.getinstance().getres("huo_png"))
		}

		/**
		 * eui complete
		 */
		private async onComplete() {
			this.load();
			this.rect.visible = false
			// await this.vsinit();
			// await this.tabarrinit();
			// await this.listeninit();
			await this.mainoutinit();

		}

		private wudao() {



		}



		/**
		 * vs init
		 */
		private vsinit() {
			this.geren = new vs(diansha.item_geren);
			this.heros = new vs(diansha.item_heros);
			this.chongwu = new vs(diansha.item_chongwu);
			this.zhuangbei = new vs(diansha.item_zhuangbei);
			this.shenqi = new vs(diansha.item_shenqi);
			this.vs.addChild(this.geren)
			this.vs.addChild(this.heros)
			this.vs.addChild(this.zhuangbei)
			this.vs.addChild(this.chongwu)
			this.vs.addChild(this.shenqi)

		}
		/**
		 * tab arr  init
		 */
		private tabarrinit() {

			this.tab.dataProvider = this.arr;
			this.tab.itemRenderer = item_bottom;
			this.arr.addItem({ label: "ziji" })
			this.arr.addItem({ label: "heros" })
			this.arr.addItem({ label: "zhuangbei" })
			this.arr.addItem({ label: "chonwgu" })
			this.arr.addItem({ label: "shenqi" })
			this.vs.selectedIndex = 0

		}


		/**
		 * listen init
		 */
		private listeninit() {
			this.tab.addEventListener(eui.ItemTapEvent.ITEM_TAP, this.itemtouch, this)
			this.change.addEventListener(egret.TouchEvent.TOUCH_TAP, this.changetouch, this)
			this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closetouch, this)
			this.mainoutbtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.mainoutbtntouch, this)
			this.zhanghao.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhanghaotouch, this)
			this.mainout.addEventListener(eui.UIEvent.CLOSING, () => {
				this.vsgroup.touchEnabled = false;
			}, this)

		}
		/**
		 * zhanghao touch
		 */
		private zhanghaotouch() {
			cores.getinstatic().changjing2.to(cores.getinstatic().login);
		}
		/**
		 * main button touch
		 */
		private mainoutbtntouch() {
			this.addChild(this.mainout);
			this.vsgroup.addEventListener(egret.TouchEvent.TOUCH_TAP, this.mainoutlisten, this)
			this.vsgroup.touchEnabled = true;
		}
		/**
		 * mainout panel init 
		 */
		private mainoutinit() {
			this.mainout.close();
			this.mainoutpointinit.x = this.mainout.x
			this.mainoutpointinit.y = this.mainout.y
		}
		/**
		 * main listen
		 */
		private mainoutlisten() {
			if (this.mainout.parent) {
				this.mainout.close()
				this.vsgroup.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.mainoutlisten, this)
				this.vsgroup.touchEnabled = false
				this.mainout.x = this.mainoutpointinit.x;
				this.mainout.y = this.mainoutpointinit.y;
			}

		}
		/**
		 * close touch
		 */
		private closetouch() {
			this.btngroup.visible = false;
			this.vs.visible = false
			this.rect.visible = false

		}
		/**
		 * change touch
		 */
		private changetouch(e: egret.TouchEvent) {
			let es: eui.ToggleButton = e.target;
			if (es.selected == true) {
				this.up()
			} else {
				this.down();
			}
		}
		/**
		 * tabup
		 */
		private itemtouch(e: eui.ItemTapEvent) {
			if (this.vs.visible == false) {
				this.btngroup.visible = true;
				this.vs.visible = true
				this.down();
			}

			this.vs.selectedIndex = e.itemIndex;

		}
		/**
		 * up
		 */
		private up() {
			this.rect.visible = true
			this.vs.height = this.vsgroup.height - this.tab.height - this.btngroup.height;
			this.btngroup.y = 53
			this.vs.y = this.btngroup.height + 53;
			this.vs.$children.forEach((v) => {
				v.height = this.vs.height;
			})

		}
		/**
		 * down
		 */
		private down() {
			this.rect.visible = false
			this.vs.height = 230;
			this.vs.y = this.vsgroup.height - this.tab.height - this.vs.height
			this.btngroup.y = this.vs.y - this.btngroup.height;
			this.vs.$children.forEach((v) => {
				v.height = this.vs.height;

			})

		}

	}
}